package com.petshop.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Check {

    /**
     * 验证手机号格式
     *
     * @param phone 手机号
     * @return 是否为手机号
     */
//    public static boolean isPhone(String phone) {
//        if (phone == null || phone.isEmpty()) {
//            return false;
//        }
//        String regExp = "/^1[3-9]\\d{9}$/";
//        Pattern p = Pattern.compile(regExp);
//        Matcher m = p.matcher(phone);
//        return m.matches();
//    }
    public static boolean isPhone(String phone) {
        /**
         * 校验手机号码是否合法
         */
        Pattern pattern = Pattern.compile("^1[3-9]\\d{9}$");
        Matcher matcher = pattern.matcher(phone);
        return matcher.matches();
    }

    /**
     * 验证密码格式
     *
     * @param password 密码
     * @return 密码是否正确
     */
    public static boolean isPassword(String password) {
        if (password == null || password.isEmpty()) {
            return false;
        }
        String regExp = "^(?=.*[a-zA-Z])(?=.*\\d)(?=.*[.,;:'\"\\\\|~@#$%_&])[\\s\\S]{8,}$";
        Pattern p = Pattern.compile(regExp);
        Matcher m = p.matcher(password);
        return m.matches();
    }

    /**
     * 验证邮箱格式
     *
     * @param email 邮箱
     * @return 邮箱是否正确
     */
    public static boolean isEmail(String email) {
        if (email == null || email.isEmpty()) {
            return false;
        }
        String regExp = "^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\\\.][A-Za-z]{2,3}([\\\\.][A-Za-z]{2})?$";

        Pattern p = Pattern.compile(regExp);
        Matcher m = p.matcher(email);
        return m.matches();
    }
}